﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;

namespace BanVeXemPhim_Presentation
{
    public class ChiTietVeDAO:DataProvider
    {
        protected override object GetDataFromDataRow(System.Data.DataTable dt, int i)
        {
            ChiTietVeDTO chiTietVeDto = new ChiTietVeDTO();
            chiTietVeDto.Cmnd = dt.Rows[i]["CMND"].ToString();
            chiTietVeDto.HoTen = dt.Rows[i]["HoTen"].ToString();
            chiTietVeDto.RapChieu = dt.Rows[i]["TenRap"].ToString();
            chiTietVeDto.IdVe = Convert.ToInt32(dt.Rows[i]["IdVe"].ToString());
            chiTietVeDto.IdGhe = Convert.ToInt32(dt.Rows[i]["Ghe"].ToString());
            chiTietVeDto.Hang = Convert.ToInt32(dt.Rows[i]["Hang"].ToString());
            chiTietVeDto.Cot = Convert.ToInt32(dt.Rows[i]["Cot"].ToString());
            chiTietVeDto.IdXuatChieu = Convert.ToInt32(dt.Rows[i]["XuatChieu"].ToString());
            return chiTietVeDto;

        }
        public ChiTietVeDTO[] DanhSachVeDatTruocTheoRap(XuatChieuDTO xuatChieuDto)
        {
            connect();
            string query = "select * from ve,ghe,xuatchieu,khachhang,rapchieu where xuatchieu.rapchieu=rapchieu.idrapchieu and ve.Ghe=ghe.idghe and ve.xuatchieu=xuatchieu.idxuatchieu and ve.khachhang=khachhang.idkhachhang and dathanhtoan=0 and ve.xuatchieu=" + xuatChieuDto.IdXuatChieu + " order by hoten";
            adapter = new SqlDataAdapter(query, connection);
            DataSet dataset = new DataSet();
            adapter.Fill(dataset);
            DataTable dataTable = dataset.Tables[0];
            int n = dataTable.Rows.Count;
            ChiTietVeDTO[] dsVe = new ChiTietVeDTO[n];
            for (int i = 0; i < n; i++)
            {
                object ve = GetDataFromDataRow(dataTable, i);
                dsVe[i] = (ChiTietVeDTO)ve;
            }
            return dsVe;
        }
    }
}
